﻿Imports System.Globalization

Public Class DOFormatter

    ''' <summary>
    ''' Converts a date into a string that can be used in a SQL insert/update/or comparison statement
    ''' </summary>
    ''' <param name="src"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function DateToString(ByVal src As DateTime) As String
        'Due to the MinValue in .Net and MSSQL2005 is different we need replacement
        If src < CType(System.Data.SqlTypes.SqlDateTime.MinValue, DateTime) Then
            src = System.Data.SqlTypes.SqlDateTime.MinValue
        End If
        If src > CType(System.Data.SqlTypes.SqlDateTime.MaxValue, DateTime) Then
            src = System.Data.SqlTypes.SqlDateTime.MaxValue
        End If
        Return src.ToString("yyyy-MM-dd HH:mm:ss.fff")
    End Function

End Class
